import requests
from bs4 import BeautifulSoup

from Crawler.baidu.baidu import hot_words

url = "https://www.baidu.com"
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"}
response = requests.get(url, headers=headers)
html = response.text

soup = BeautifulSoup(html,'html.parser')

hot_words_elements = soup.find_all('span',class_='title-content-title')

hot_words = [element.text.strip() for element in hot_words_elements]


with open('hot_words.txt','w',encoding='utf-8') as f:
    f.write('热搜词\n')
    for word in hot_words:
        f.write(word+'\n')

